package com.pfizer.Utils;

import java.io.InputStream;
import java.net.URL;

import android.content.Context;

import com.pfizer.DB.DataHelper;
import com.pfizer.DownLoad.AsyncUserInfoXMLDownloader;
import com.pfizer.Entity.UserInfo;
import com.pfizer.pfizerExpertForPad.pfizerApplication;

/**
 * UserHelper：用於認證登陸用戶是否有效
 * 
 * @author krui
 * @version 1.3 2011/11/22
 * 
 * @see com.pfizer.pfizerExpertForPad.pfizerApplication
 * @see com.pfizer.DB.DataHelper
 */
public class UserHelper {
	Context mContext;
	UserInfo user;
	private String UserInfoUrlFormat = "%s/PENS_CRC/Query.aspx?Switch=UserLogin&UserId=%s&UserPass=%s&Obj_From=%s&Obj_ID=%s&ProveCode=%s";
	pfizerApplication pApplication;
	URL url = null;
	InputStream inputStream = null;
	DataHelper dbHelper;
	boolean isConfirm = false;

	/**
	 * 構造函數
	 * @param user
	 * @param mContext
	 * @param dbHelper
	 * @param isConfirm
	 */
	public UserHelper(UserInfo user, Context mContext, DataHelper dbHelper,
			boolean isConfirm) {
		this.user = user;
		this.mContext = mContext;
		this.dbHelper = dbHelper;
		this.isConfirm = isConfirm;
	}
/**
 * 此方法用於認證用戶
 */
	public void UserConfirm() {

		pApplication = new pfizerApplication();
		String urlStr = String.format(UserInfoUrlFormat, pApplication.getWebUrl(),
				user.getUserID(), user.getUserPsw(), pApplication.getObjFrom(),
				pApplication.getObjID(), pApplication.getUserLoginProveCode());
		//urlStr = "http://222.196.236.62/xml/userinfo.xml";
		//在線程中獲取用戶信息，後臺判定
		new AsyncUserInfoXMLDownloader(mContext, urlStr, user, dbHelper,
				isConfirm).execute();
	}

}
